$(window).on("load", function () {
    //轮播图
    $(function () {
        var myTop = 100; //这是表示层级
        var sx = 0;
        var speed = 720
        var timer = null;
        $(".con2Center ol li").on("click", function () {
            myTop++;
            $(this).addClass("current").siblings("li").removeClass("current");
            var index = $(this).index();
            $('.con2Center ul li').eq(index).css("z-index", myTop).hide().fadeIn()
            sx = index;
        });
        var flag = true;
        $(".con2Center .right").click(function (e) {
            if (flag) {
                flag = false;
                sx++;
                myTop++;
                if (sx > 2) {
                    sx = 0
                }
                $(".con2Center ol li").eq(sx).addClass("current").siblings().removeClass();
                $(".con2Center ul li").eq(sx).css({
                    zIndex: myTop
                }).hide().fadeIn(2000, function () {
                    flag = true;
                });
            }
        })
        var flag = true;
        $('.con2Center .left').click(function (e) {
            if (flag) {
                flag = false;
                sx--;
                myTop++;
                if (sx < 0) {
                    sx = 2
                }
                $('.con2Center ol li').eq(sx).addClass('current').siblings().removeClass();

                $('.con2Center ul li').eq(sx).css({
                    zIndex: myTop
                }).hide().fadeIn(1000, function () {
                    flag = true;
                });
            }
        });
        timer = setInterval(autoPlay, 2000);

        function autoPlay() {
            myTop++;
            sx++;
            if (sx > 2) {
                sx = 0
            }
            $('.con2Center ol li').eq(sx).addClass('current').siblings().removeClass();
            $('.con2Center ul li').eq(sx).css({
                zIndex: myTop
            }).hide().fadeIn(speed);
        }
        $(".con2Center").hover(function (e) {
                clearInterval(timer)
                $('.con2Center span').fadeIn();
            },
            function (e) {
                clearInterval(timer)
                timer = setInterval(autoPlay, 2000)
                $('.con2Center span').fadeOut()
            });
    })
    //导航栏悬停
    $(function () {
        var topH = $(".navTop").height();
        $("body").on("scroll", function () {

            var mH = $(this).scrollTop();
            if (mH >= topH) {
                $(".navCon").css({
                    position: "fixed",
                    top: 0,
                    zIndex: 999
                });
                $(".bigCon").css("marginTop", $(".navCon").height())
            } else {
                $(".navCon").css("position", "static");
                $(".bigCon").css("marginTop", "0");
            }
        })
    })
    //小火箭悬停
    $(function () {
        var pagH = 900;
        $("body").on("scroll", function () {
            console.log(11111)
            var mH = $(this).scrollTop();
            if (mH >= pagH) {
                $(".con11").css({
                    display: "block",
                });
            } else {
                $(".con11").css({
                    display: "none",
                });
            }
        })
        $(".con11").on("mouseenter", function () {
            $(".rocket").css({
                "background": "url(../images/rocket2.png)no-repeat",
            })
        }).on("mouseleave", function () {
            $(".rocket").css({
                "background": "url(../images/rocket.png)no-repeat",
            })
        }).on("click", function () {
            $('body,html').animate({
                scrollTop: 0
            }, 500, function () {
                console.log(222222)
            })
        })

    })


    //tab切换
    $(function () {
        $(".popo").find("li").on("click", function () {
            var $index = $(this).index();
            $(this).addClass("active").siblings("li").removeClass("active");
            $(".centerCon").eq($index).addClass("selected").siblings("div").removeClass("selected")
        })
    })


    //数据渲染
    $(function(){
        $.ajax({
            url:"http://127.0.0.1:8080/api/goods",
            type:"get",
            dataType:"json"
        }).done((data)=>{
             console.log(data)

            data.forEach(ele => {
                console.log(ele.imgs[0])
                var strHtml=`<div class="con5_1L con5_1c">
                <a href="./goods.html?pid=${ele.pid}"><img src="http://127.0.0.1:8080${ele.imgs[0]}" alt=""></a>
                <div class="con5_1L0">
                    <p><a href="#">${ele.pName}</a></p>
                    <div class="p1">
                        <div class="quan">
                            <span class="quan-left"></span>券<span><b><span>￥</span>2000</b></span>
                            <span class="quan-right"></span>
                        </div>
                        <span class="outTime">
                            过期时间<span style="font-family: Arial; margin-left: 6px;">2019-07-29</span>
                        </span>
                    </div>
                    <div class="p2">
                        优惠券剩余<span class="color_p">89000</span>张，已领取
                        <span class="color_p">11000</span> 张
                    </div>
                    <div class="p3">
                        销量<span class="color_p">970333</span>件
                    </div>
                    <div class="p4">
                        <div class="buy_price">${ele.pPrice}</div>
                        <div class="old_price">
                            <p>
                                <span>￥</span>9900
                            </p>
                            <span class="later_price">券后价</span>
                        </div>
                        <div class="gobuy">
                            <a href="#">
                                去下单
                                <span></span>
                            </a>
                        </div>
                    </div>
                </div>
            </div>`
            $(".gs").append(strHtml);
            }); 
        })
    })



})